import cloud from '@lafjs/cloud'
let data
let dbName = "file-list"

export default async function (ctx: FunctionContext) {
  data = ctx.body.data
  switch (ctx.body.type) {
    case "list":
      return await list()
      break;

    default:
      break;
  }
}

async function list() {
  let whereJson = { ...data }
  delete whereJson.pageIndex
  delete whereJson.pageSize
  let res = await cloud.nw.db.select({
    dbName,
    getCount: true,
    pageIndex: data.pageIndex,
    pageSize: data.pageSize,
    whereJson: whereJson,
    sortArr: [{ "name": "_add_time", "type": "desc" }]
  });
  return cloud.utils.requestReturn({ data: res })
}
